package com.shenzhenai.composebasic.components

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 12/9/2025 下午11:49 周五
 * @description
 *
 * Box 用法 (类似 FrameLayout, 堆叠布局)
 * https://www.bilibili.com/video/BV1pi4y127HC?vd_source=e07cc8cc94eb22bd76722071b03cd199&spm_id_from=333.788.player.switch
 *
 */

@SuppressLint("UnusedBoxWithConstraintsScope")
@Composable
fun BoxSample() {
//    Box {
////        Text(text = "Text 1")
////        Text(text = "Text 2")
//
//        Box(
//            modifier = Modifier
//                .size(200.dp)
//                .background(Color.Blue)
//        )
//
//        Box(
//            modifier = Modifier
//                .size(100.dp)
//                // 让当前盒子位于父容器的中间
//                .align(Alignment.Center)
//                .background(Color.Green)
//        )
//    }


    BoxWithConstraints() {
        if (maxWidth < maxHeight) {
            Box(
                modifier = Modifier
                    .size(200.dp)
                    .background(Color.Blue)
            )
        } else {
            Box(
                modifier = Modifier
                    .size(100.dp)
                    // 让当前盒子位于父容器的中间
                    .align(Alignment.Center)
                    .background(Color.Green)
            )
        }

    }
}

@Preview
@Composable
fun BoxSampleSample() {
    BoxSample()
}